package edu.wtbu.cs.androiddemo.net;


import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import edu.wtbu.cs.androiddemo.R;

public class GoodsListAdapter extends RecyclerView.Adapter<GoodsListAdapter.ViewHolder> {
    private List<GoodInfo> mList;
    private Activity mActivity;
    private ViewHolder viewHolder;
    private GoodInfo goodInfo;
    public GoodsListAdapter(Activity activity, List<GoodInfo> list) {
        mList = list;
        mActivity = activity;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        viewHolder = new ViewHolder(View.inflate(mActivity, R.layout.goods_list_items, null));
        return viewHolder;
    }
    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        goodInfo = mList.get(position);
       // Glide.with(mActivity).load(goodInfo.getImage()).into(holder.imageView);
        holder.title.setText(goodInfo.getName());
        holder.price.setText(""+goodInfo.getPrice());
        holder.count.setText(goodInfo.getVolume()+"人付款");
        holder.address.setText(goodInfo.getProductLocation());
        holder.shopName.setText(goodInfo.getShopName());
        holder.imageView.setImageURL(goodInfo.getImage());
    }
    @Override
    public int getItemCount() {
        return mList.size();
    }
    class ViewHolder extends RecyclerView.ViewHolder {

        TextView shopName;
        TextView title;
        TextView count;
        TextView address;
        TextView price;
        MyImageView imageView;
        View functionView;
        public ViewHolder(View itemView) {
            super(itemView);
            functionView = itemView;
            imageView = itemView.findViewById(R.id.iv_iamge);
            title = (TextView)itemView.findViewById(R.id.tv_title);
            count = (TextView)itemView.findViewById(R.id.tv_count);
            address = (TextView)itemView.findViewById(R.id.tv_address);
            price = (TextView)itemView.findViewById(R.id.tv_new_price);
            shopName =(TextView) itemView.findViewById(R.id.tv_shopname);
        }
    }
}
